<template>
  <span>
    <ElButton v-if="drawBtn" type="primary" plain @click="doDrawTask()"> 提取 </ElButton>
    <ApprovalMessageModel ref="approvalMessageModel" :visible.sync="visibleMessageModel" @getMessage="getMessage" />
  </span>
</template>

<script>
  import { checkHistoryTaskDraw, drawHistoryTask } from '@/api/admin/workitem'
  import { mapState } from 'vuex'
  import ApprovalMessageModel from '@/module/process/components/ApprovalMessageModel'

  export default {
    name: 'FlowableHandleDraw',
    components: {
      ApprovalMessageModel
    },
    props: {
      // 参数对象
      propParams: {
        type: Object
      }
    },
    data() {
      return {
        drawBtn: false,
        visibleMessageModel: false
      }
    },
    computed: {
      ...mapState('user', ['sysUser'])
    },
    created() {
      this.initParams(this.propParams)
    },
    methods: {
      initParams() {
        checkHistoryTaskDraw(this.propParams).then(response => {
          this.drawBtn = response.data.data
        })
      },
      init(paramsObj) {},
      doDrawTask() {
        this.visibleMessageModel = true
        this.$refs.approvalMessageModel.showModel('draw', '请输入提取意见！')
      },
      getMessage(message, type) {
        if (type === 'draw') {
          this.propParams.message = message
          drawHistoryTask(this.propParams).then(response => {
            const data = response.data
            if (data.code === 0) {
              this.$message.success(data.msg)
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      }
    }
  }
</script>
